$(function() {
	var parId = getUrlParameter("parId");
	// 根据参数名称获取value
    function getUrlParameter(paramKey) {
        var sURLVariables, i, sParameterName, sPageURL = window.location.search.substring(1);
        if (sPageURL) {
            sURLVariables = sPageURL.split("&");
            for (i = 0; i < sURLVariables.length; i++) {
                sParameterName = sURLVariables[i].split("=");
                if (sParameterName[0] === paramKey) return sParameterName[1]
            }
        }
    }	
	//Load left menu tree
	var leftMenu = new Object();
	leftMenu.htmlss = "";
	leftMenu.index = 0;
	leftMenu.countIco = 0;
	//Load tree dom
	leftMenu.lookTree = function(jsonObj) {
		//if(jsonObj.permissionId!=3){
			var url = "";
			if(jsonObj.requestUrl == "") {
				url = "javascript:void(0);";
			}else{
				url = basePath + jsonObj.requestUrl + "?parId=" + jsonObj.permissionId;
			}
			if(leftMenu.index == 0){
				//增加id为currentId0的目的是使'首页'高亮显示
				leftMenu.htmlss = "<div class='itemli StartStyleItemli' id='currentId0'><a href='" + basePath + "index.jsp?parId=0'><b class='it0'></b>首页</a></div>";
			}
			if(leftMenu.index == 1) {
	//				实现侧边栏的图标选择
				leftMenu.countIco = leftMenu.ico(jsonObj.permissionId);
				leftMenu.htmlss += "<div class='itemli' id='currentId" + jsonObj.permissionId + "'><a href='" + url + "'><b class='it" + leftMenu.countIco + "'></b>" + jsonObj.permissionName + "</a></div>";
			}	
			if(jsonObj.menus!=undefined && jsonObj.menus.length > 0) {
				leftMenu.index += 1;
				for(var nn = 0; nn < jsonObj.menus.length; nn++) {
					//循环加入左边菜单栏的内容
					leftMenu.lookTree(jsonObj.menus[nn]);
				}
				leftMenu.index -= 1;
			}
		//}
	}
	leftMenu.addHtml = function(obj) {
		var clear = "<div class='clear'></div>";
		obj.html(leftMenu.htmlss + clear);
		$("#currentId" + parId).addClass("cur");
	}
	leftMenu.qOrgTree = function() {
		$.ajax({
			type: "POST",
			url: basePath + "user/queryByUserMenus.do",
			cache: false,
			success: function(data) {
				if(data.returnCode == 10000) {
					leftMenu.lookTree(data.returnData);
					leftMenu.addHtml($("#leftMenuArea"));
					$("#userId").val(data.returnData.userId);
					$("#userTypeNow").val(data.returnData.userType);
				} else if(data.returnCode == 999994) {
					setUserTimeout(data);
				} else {
					layer.msg(data.returnMessage, 2, -1);
				}
			},
			error: function(message) {
				layer.msg("加载菜单列表失败！<br>" + message, 2, -1);
			}
		});
	}
	leftMenu.ico = function(id) {
		var icoNum = null;
		switch(id) {
			case 1:
				icoNum = 1; //信息管理
				break;
			case 2:
				icoNum = 2; //方案管理
				break;				
			case 3:
				icoNum = 3; //报告管理
				break;
/*			case 3:
				icoNum = 5; //配置管理
				break;*/				
			case 4:
				icoNum = 6; //资源调配
				break;
			case 5:
				icoNum = 4; //客户管理
				break;
			case 6:
				icoNum = 7; //系统管理
				break;
			default:
		}
		return icoNum;
	}
	leftMenu.qOrgTree();
});